System and method for managing a cache memory

ABSTRACT

A processing system optimized for data string manipulations includes data string execution circuitry associated with a bus interface unit or memory controller. Cache coherency is maintained, and data move and compare operations may be performed efficiently on cached data. A barrel shifter for realignment of cached data during move operations and comparators for comparing a test data string to cached data a cache line at a time may be provided.

REFERENCE TO RELATED APPLICATION

The present application is a divisional of, and claims priority benefitunder 35 U.S.C. § 120 from, U.S. application Ser. No. 09/178,196 filedOct. 23, 1998, entitled “PROCESSING SYSTEM WITH SEPARATE GENERAL PURPOSEEXECUTION UNIT AND DATA STRING MANIPULATION UNIT,” now U.S. Pat. No.6,658,552 issued Dec. 2, 2003. which is incorporated herein byreference.

BACKGROUND OF THE INVENTION

1. Field of the Invention

The invention relates to digital data processing circuits. Inparticular, the invention relates to the performance of datamanipulation functions performed on strings of data elements.

2. Description of the Related Art

Conventional microprocessing circuits include several common buildingblocks. Essentially all such systems include a main memory storage areafor storing data and instructions, and an execution unit for operatingon the data in accordance with the instructions. After the functionspecified by a given instruction is performed, processed data isreturned to the main memory storage area.

Increases in processor performance have been obtained by enhancements tothis fundamental scheme. The processor may include two or more separateexecution units which can process multiple instructions in parallel. TheIntel Pentium and Pentium Pro are two examples of this type ofprocessor. In some cases, different execution units are dedicated todifferent functions. The Intel Pentium Pro, for example, includesseparate execution units for floating point and fixed point arithmeticoperations. Another performance enhancement in almost universal use isthe provision of data and instruction caches which provide local storageof recently used data and instructions. This speeds the fetching andstoring of data and instructions by reducing the number of memoryaccesses required from a typically much slower main memory storage area.

Still, some types of operations are performed inefficiently by theseprocessor architectures. One inefficiently performed class ofinstructions is data string manipulation instructions. In theseinstructions, operations involving a sequence of data elements areperformed. For instance, a block of data may be moved from one series ofmemory addresses to another series of memory addresses. Alternatively,the elements of a block of data may be compared to a test data elementor a string of test data elements. In the Intel Pentium Pro, assemblylanguage instructions are provided to perform these functions on aspecified string of data. Although the total length of the processedstring can be very large, data is moved and/or analyzed as short stringportions of at most 32 bits long due to the bus width and 32 bitexecution unit. Performing a string move on the Pentium Pro thusinvolves a sequential process of reading and writing pieces of the datastring to and from main memory (or to and from the cache for thoseportions of the string which are present there). String scans formatching data are similarly performed. Short pieces of the string areread from memory and compared to the desired test string. Thus, thePentium Pro architecture includes useful string instructions as part ofits instruction set, but is incapable of performing string operations onlarge strings as quickly as memory technology might allow.

Another commercially available device which includes string manipulationfeatures is the TMS320C80 digital signal processor from TexasInstruments. Because this device is adapted for use in video andmultimedia applications, features for improving the speed of movement oflarge blocks of data such as a set of image pixels are included. In theTMS320C80, the programmer may write string movement parameters to amemory location. These string movement parameters can then betransferred to the memory controller portion of the device, and thestring movement is performed by the memory controller without furtherinvolvement of the execution unit. This feature helps speed up themovement of data blocks, but setting up the transfer parameters requirespreliminary write operations, which is inconvenient for the programmer,and results in the need to use several instructions to initiate a blockmove. Furthermore, although the TMS320C80 includes a data cache, thesememory move operations are not performed utilizing cached data, and nomechanism to ensure cache coherency with the main memory where the datamove occurs is provided.

Other implementations of memory systems which can perform datamanipulation have been described. In U.S. Pat. No. 5,590,370, a systemis disclosed which includes “active memory elements” that incorporateprocessing logic for performing searches and other data manipulationsoutside of the host processing circuit. U.S. Pat. No. 4,731,737 alsodiscusses memory elements which can receive data manipulation commandsfrom an external host processor. However, neither of these systemsprovide for cache coherency, and they further do not describe the use ofassembly language instruction sets which provide simple and efficientprogramming of data string manipulations. Thus, there is a continuingneed for improvements in processor architectures to allow the processingof data strings quickly and efficiently.

SUMMARY OF THE INVENTION

A digital processing system optimized for string manipulations comprisesan instruction fetch unit coupled to an external memory, a firstexecution unit coupled to receive, decode, and perform assembly languagearithmetic and logic instructions received from external memory via theinstruction fetch unit, and a second execution unit coupled to receive,decode, and perform assembly language string manipulation instructionsreceived from external memory via the instruction fetch unit.Instructions may be analyzed to detect data string operations forrouting to the appropriate execution unit.

In systems with data caching, data may be reassigned from a first memorylocation to a second memory location by writing a value to an entry in acache tag memory without changing the content of an entry in a cachedata memory associated with the entry in the cache tag memory. In someembodiments, data move operations include reading a cache linecontaining at least a portion of data from a data cache; shifting thecache line a selected amount, and storing the cache line in the datacache.

Compare operations in systems with data caching are also optimized.Accordingly, a cache memory system may comprise a data memory configuredto hold cache lines comprising a plurality of bytes of data and aplurality of comparators, wherein each comparator has a first inputcoupled to the data memory such that each comparator receives one of theplurality of bytes of data via its associated first input, and whereineach comparator has a second input coupled to a second data source,whereby the cache line may be compared to data received from the seconddata source. The second data source may comprise external stringmanipulation circuitry.

BRIEF DESCRIPTION OF THE DRAWINGS

FIG. 1 is a block diagram of a processor circuit according to oneembodiment of the invention.

FIG. 2 is a block diagram of a processor circuit according to a secondembodiment of the invention.

FIG. 3 is a flow chart illustrating a data string manipulation performedin a processing circuit according to one embodiment of the invention.

FIG. 4 is a block diagram of a memory controller circuit for receivingand performing data string manipulation instructions.

FIG. 5 is a block diagram of a processor circuit according to oneembodiment of the present invention including first and second datacaches.

FIG. 6 is a block diagram of a two-way set associative data cacheincluding string move circuitry for fast string move operations.

FIG. 7 is a block diagram of data cache circuitry for fast string scanoperations.

DETAILED DESCRIPTION OF THE INVENTION

Embodiments of the invention will now be described with reference to theaccompanying Figures, wherein like numerals refer to like elementsthroughout. The terminology used in the description presented herein isnot intended to be interpreted in any limited or restrictive manner,simply because it is being utilized in conjunction with a detaileddescription of certain specific embodiments of the invention.

Referring now to FIG. 1, a processing system according to one embodimentof the invention is illustrated. The processing system of FIG. 1includes a central processing unit (CPU) 10, which is coupled to a mainmemory 12 through a memory controller 14. Main memory 12 typicallycomprises dynamic random access memory (DRAM) circuits. These memorydevices send and receive data elements to and from the memory controller14 in response to control signals which include row and column addressesspecifying desired data elements. As used herein, a data elementcorresponds to the data associated with a single address in the addressspace supported by the processing system. Depending on the processingsystem, a data element may be a single bit, an 8 bit byte, or may be 64or more bits long. In the Pentium architecture referred to throughoutthis specification, a data element is an 8 bit byte.

Different control signal formats may be used with different types ofmemory devices 12. Some types of DRAM circuits are adapted toefficiently store and retrieve strings of data from consecutiveaddresses. Page mode DRAMs, for instance, will output a sequence of dataelements having a common row address without needing to re-receive thesame row address with each DRAM access. Synchronous DRAM (SDRAM)memories are clocked devices which include a mode register which isloaded with an access burst length definition. In these devices, allaccesses are burst mode. Consecutive data elements are placed on thedata output pins in each clock cycle in response to a single presentedstarting address and the burst length definition. The memory controller14 used in the processing system of FIG. 1 will be configured tointerface appropriately to whatever type of memory device 12 is beingutilized.

It is one aspect of many prior art processing systems that stringmanipulation instructions are performed without fully exploiting theburst data access capabilities of certain DRAM devices. As mentionedabove, string instructions are often performed on small segments of thestring at a time. This requires alternating between reading and writingthe string data elements, thereby preventing the possibility of takingadvantage of long burst reads and writes whereby the same total numberof read and write operations can be performed more quickly. Thus, aswill be seen more fully below, the invention has advantageousapplication to processing systems which incorporate a main memory 12which supports burst mode data accesses such as an SDRAM device.

The CPU 10 includes a first execution unit 16 for performinginstructions. It will be appreciated that the execution unit 16 willgenerally include several components, including an instruction register,an instruction decoder, one or more ALUs, as well as possibly data andinstruction caches. The execution unit 16 receives data and instructionsfrom a bus interface unit 18 which communicates with the memorycontroller 14. In operation, instructions and data are received by theexecution unit 16, the data is processed in accordance with theinstructions, and the processed data is returned to the memory 12.

In one embodiment of the invention, not all of the instructions receivedby the first execution unit 16 are performed under its control. In thisembodiment, string manipulation instructions received by the executionunit 16 are forwarded to a second execution unit 20 separate from thefirst execution unit 16. As string manipulations involve heavy memoryaccess traffic, it is advantageous to associate this second executionunit 20 with either or both of the memory controller 14 or the businterface unit 18, as these two units may be directly involved withcontrolling memory accesses. FIG. 1 illustrates an embodiment whereinstring instruction execution circuitry 20 is associated with the businterface unit 18. FIG. 2 illustrates an embodiment wherein stringinstruction execution circuitry 20 is associated with the memorycontroller 14.

It will be appreciated that the location of string execution circuitrymay vary depending on the design and location of main memory 12, cachememories (not shown in FIGS. 1 and 2), and the memory controllercircuitry 14. Systems without data cache capabilities and an off chipmain memory and memory controller may include essentially all of thestring manipulation execution circuitry on the off chip memorycontroller. In Pentium processor based architectures, commonlyimplemented hardware configurations include a data cache on theprocessor integrated circuit accessed by the bus interface unit, and asecond data cache and main DRAM memory external to the processor. Thesecond data cache and main DRAM memory are accessed by an externalmemory control and bus bridge chipset which provides an interfacebetween the processor and the second off chip data cache and the mainmemory. The Pentium Pro architecture incorporates the second data cacheonto a single module with the processor integrated circuit such thatboth the first and second data caches are controlled by the businterface unit on the processor integrated circuit. In these typicalPentium and Pentium Pro configurations, string execution circuitry maybe provided both on the processor integrated circuit in association withthe bus interface unit and on the off chip memory controller integratedcircuit. In this way, string manipulations may be efficiently performedon cached and uncached data. As a final example, the TMS320C80 processordescribed above includes a data cache and a portion of main memory onthe processor integrated circuit. The on chip bus interface unit of thisdevice also includes integral DRAM memory control circuitry forinterfacing to off chip main memory without an intervening memorycontroller integrated circuit. In this type of architecture, the stringexecution circuitry will advantageously be entirely located on theprocessor integrated circuit in association with the bus interface unit.

It will be appreciated that the principles of the invention areapplicable to any variety of circuit element placement and distributionof memory and memory control devices. In any of these applications,manipulations of strings of data may be performed by circuitryassociated with memory control. This circuitry will be configured tointerface with the memory technology being used by the processingsystem, and can take advantage of the block read and write features ofdifferent DRAM memory devices when performing string manipulationinstructions.

FIG. 3 illustrates a procedure which may be performed by the systemarchitectures illustrated in FIGS. 1 and 2. The process begins at startblock 26 and proceeds to block 28 where an instruction is fetched frommemory. Depending on the data storage format of the system, thisfetching may be from main memory or an instruction cache. After beingfetched, the instruction is analyzed at block 30 in order to determineat decision block 32 whether or not the instruction calls for a datastring manipulation. If the instruction does not call for a stringmanipulation, at block 34 the instruction is issued to the generalexecution unit which services non-string arithmetic, logical, or otherdata processing operations. If the instruction does call for a datastring manipulation, at block 36 it is sent to the string executioncircuitry for processing. Following instruction issuance, the sequencecontinues at block 38. Thus, assembly language instructions for datastring operations are recognized and issued to a dedicated processingunit for processing in a manner which is optimized for the memorytechnology utilized in the processing system.

Referring now to FIG. 4, a memory controller 40 incorporating stringexecution circuitry is illustrated. In the embodiment of FIG. 4, thememory controller 40 resides on a separate integrated circuit from theprocessor. As in conventional memory controller integrated circuits,host processor control interface circuitry 42 and DRAM memory controlinterface circuitry 44 is provided. The host control interface 42includes an address bus 46 and several other control signals 48 whichinitiate and define bus cycles and otherwise control data transferbetween the host processor and the memory controller. The memoryinterface 44 also includes an address bus 50, and standard DRAM memorycontrol signals such as row and column address strobes. In systems witha data cache separate from the processor integrated circuit, the memorycontroller 40 may additionally include an SRAM interface (not shown inFIG. 4) for retrieval and forwarding of cached data to the hostprocessor. The memory controller 40 also includes a data bus 52 coupledto the host processor, and a second data bus 54 coupled to the memorydevices. A set of data buffers 56 temporarily store data as it passesthrough the memory controller circuit.

In accordance with one embodiment of the invention, the memorycontroller circuit 40 further includes an instruction register 58 and aninstruction decoder 60. The instruction register 58 may be configured toreceive string instructions from the host processor and to forward thosestring instructions to the instruction decoder 60. The instructionregister 58 may be configured as a multi-instruction buffer so that aseries of data string instructions can be queued in the memorycontroller 40. The decoder 60 controls the memory interface 50 and databuffers 56 to perform data string manipulations such as string moveswithout further involvement of the host processor. During a string moveoperation, for example, the decoder 60 may control the memory interfaceso as to load a source string into a data buffer among the data bufferset 56, and then write this source data back to the main memory at itsdestination addresses.

It will be appreciated that although FIG. 4 illustrates a memorycontroller on a separate integrated circuit from the host processor,some or all of the circuitry shown in FIG. 4 may be incorporated ontothe same integrated circuit as the processor, or may be split amongseveral additional integrated circuits. For example, the memory controlinterface 44 could be incorporated into a processor bus interface unit,and is so incorporated in some commercially available signal processors.As another alternative, some commercially available memory controllerand bridge chip sets place the data buffers 56 on a separate integratedcircuit from the memory interface 44. The invention has application toall of these alternative designs.

Methods of issuing instructions to particular execution units dedicatedto particular tasks are well known, and a wide variety of techniques maybe used. Instruction dispatching to multiple execution units isperformed in many commercially available microprocessors and digitalsignal processors, including the Pentium and Pentium Pro. If the stringexecution circuitry is on the same integrated circuit as the otherexecution units of the processor, multiple busses connecting aninstruction dispatch unit to the various execution units, including thestring execution unit, may be used for proper string instructionrouting.

Sending string instructions to an off chip memory controller may also beaccomplished in a variety of ways. It would be possible, for example, toinclude a dedicated set of signal lines between the host processor andthe off-chip memory controller for passing string manipulationinstructions. In other embodiments, however, string instructions may bepassed in ways which do not require modification of the currently usedphysical interfaces between host processors and off chip bridge andmemory controller circuits.

In conventional memory controllers, the host processor uses several ofthe control signals 48 to initiate and define bus cycles for performingdifferent types of data transfer operations. Memory read, memory write,I/O read, and I/O write are four bus cycle examples. When the hostprocessor asserts a selected set of control signal lines, the memorycontroller becomes configured to communicate with the processoraccording to the requested operation. This type of interface protocol iscurrently used to transfer setup information from the host processor tointernal configuration registers in memory controllers, and can also beused in an analogous manner to transfer string instructions to aninstruction register 58 internal to the memory controller. Oneconvenient method of accomplishing this would be to use an I/O write buscycle to transfer data to an I/O address that is mapped to theinstruction register 58. In this case, information from the processorwhich comprises the string manipulation opcode and its associatedparameters is loaded from the data bus 52 into the instruction register58 in response to an I/O write command directed to that address.

An I/O write bus cycle may also be directed to an address not normallyused for I/O devices. In the Intel Pentium architecture, I/O operationsare limited to the bottom 64 k of address space. In this embodiment, amemory controller in accordance with the invention may receive a commandto perform an I/O write bus cycle, but receive a write address which isset to a unique pre-defined configuration defining an address outsidethe normal 64 k I/O address space. If this occurs, the memory controllercan be configured to recognize this as a command to accept a stringmanipulation op-code and its associated parameters from the host databus 52, and the memory controller will load information which followsfrom the processor into the instruction register 58.

Based on the foregoing description, it can be appreciated that the mostadvantageous application of the above described principles will varywith various processor architectures. The presence and location of datacaches, the types of string manipulation instructions supported in theprocessor instruction set, the degree of incorporation of memory controlcircuitry on the processor integrated circuit, and other factors willinfluence the optimal functionality and location of dedicated stringmanipulation circuitry.

Accordingly, and referring now to FIG. 5, an example implementation ofstring manipulation optimization according to the invention is provided.For this example, a processor architecture based on the Intel PentiumPro design is used for illustration. The processor 64 of FIG. 5 includesa bus interface unit 66 which provides communication with off chip mainmemory via external address, data, and control busses 70. As will bealso discussed in more detail below, these busses 70 may couple to amemory controller like that illustrated in FIG. 4. The bus interfaceunit 66 also communicates with a Level 1 data cache 72 and a Level 2data cache 74. In the Pentium Pro, for example, the Level 1 cache is a 8kB cache on the same die as the processor, and the Level 2 cache is a256 kB cache located in the processor module but on a separate die.

Instructions are fetched and cached from external memory by aninstruction fetch unit 76, and are forwarded to an instruction decoder78 which decodes each assembly language instruction and converts it intotwo or more simple micro-operations. The micro-operations are routedinto an instruction pool 80 where they await dispatch to an appropriateexecution unit. After execution by an execution unit 82,micro-operations are retired by a retirement unit 86, and the processorstate is updated by writing results to memory or to an on-board registerfile 88. The processor design illustrated in FIG. 5 can be made tosupport branch prediction, as well as out of order and speculativeinstruction execution. All of these features will affect the optimalmethods of issuance and execution of string instructions.

In a conventional processor architectures of this type, such as in thePentium Pro design, string manipulation instructions are treated thesame as arithmetic and logical instructions. String moves, for example,are treated as sequences of individual data move operations. A commandMOVSB (part of the Pentium Pro instruction set) is an example of anindividual data move operation. This command moves a byte of data from asource address to a destination address. The source and destinationaddresses are loaded in source and destination address registers in theregister file 88. In the Pentium Pro, these registers are referred to asthe SI and DI registers. The MOVSB command also has the automatic effectof incrementing the addresses stored in the SI and DI registers by one.These registers may alternatively be decremented by one, depending onthe status of a flag also located in the register file 88. Individualdata move commands of word and doubleword size are also provided, and inthese cases, the SI and DI registers are incremented or decremented by 2or 4 respectively.

Although a string move may be programmed using an individual data moveoperation in a loop, it can be advantageous to include stringmanipulation instructions in the assembly language instruction set. Thisis done in the Pentium Pro by allowing the programmer to include a REPprefix in front of the data move instruction. The command REP MOVS, forexample, repeats an individual byte, word, or doubleword move until acount register in the register file 88 becomes zero. During the stringmove operation, the SI and DI registers are appropriately incremented ordecremented with each individual data move, and the count register isalso decremented. This continues until the count register reaches zero,at which point the move operation terminates. Thus, in conventionalsystems, string move operations are converted into long sequences ofindividual load, store, and branch micro-operations by the instructiondecoder 78. These micro-operations are executed by the general executionunit 82 one at a time.

In contrast, in an embodiment of the invention shown in FIG. 5, a stringmanipulation instruction is not converted into a sequence ofmicro-operations by the decoder 78. Instead, the string manipulationinstructions may be directly forwarded essentially undecoded to theinstruction pool 80. In the instruction pool 80, the instructions areanalyzed to recognize string manipulation opcodes. When one is detected,this instruction is issued to the string execution circuitry 84 in thebus interface unit 66. The bus interface unit 66 may in turn forward thestring manipulation instruction to an external memory controller havingstring execution circuitry, if the manipulation is to be performed inoff chip main memory.

As mentioned above, the instructions in the instruction pool 80 may beexecuted out of the original program order, and may be executedspeculatively as part of a predicted branch which has not yet beentaken. In this type of architecture, instruction analysis circuitryassociated with the instruction pool 80 must monitor data dependenciesamong instructions. For the string manipulation instructions, issuanceto the bus interface unit 66 will generally await the completion of anyinstruction which modifies data in source or destination address blocks.Subsequent instructions which overwrite source data or read fromdestination data should also await completion of the string manipulationinstruction prior to being executed. String manipulation instructionssuch as a string move involving write operations should not be executedspeculatively as part of a predicted branch, as there is no way totransparently undo the write if the predicted branch is not taken.Although the instruction analysis circuitry associated with theinstruction pool 80 may need to be more complex than in conventionalprocessors due to the need to evaluate data dependencies regardingblocks of addresses, implementation would be a straightforwardenhancement to logic currently provided in conventional microprocessors.

A string move instruction in the present architecture may thus beexecuted as follows, ignoring, for the moment, the possibility thatsource and/or destination data is cached on the processor chip. Theformat for the instruction will include a string move opcode, as well asthe starting source address, the starting destination address, the sizeof the data elements to be moved (i.e. byte, word, doubleword, etc.) anda count indicating the number of data elements to be moved. It may benoted that conventional register architectures associated withindividual data move operations need not be altered even if the stringmove operation is performed off-chip. At the time the instructionop-code and parameters are issued to the bus interface unit 66, thestarting source and destination addresses can be appropriatelyincremented or decremented in a single cycle by the amount indicated bythe value of the count parameter. Circuitry to perform this function maybe present in the bus interface unit 66. These new values can beimmediately loaded into the SI and DI registers in the register file 88without going through the conventional sequential incrementing ordecrementing as the string move operation proceeds. The count registercan simply be cleared. The processor now has its on board SI, DI andcount registers in the same state they would be in had the string movebeen accomplished in a conventional manner. The string move opcode andparameters can be routed off-chip, and the string move may proceedwithout further processor involvement.

Normally, the processor operates on virtual addresses, and the memorycontroller and main memory operate with physical addresses. Addresstranslation takes place in the processor prior to issuing memory accessrequests to external memory. Either the same virtual to physical addresstranslation must be performed by the processor prior to sending stringmove parameters off-chip, or the processor must provide addresstranslation information to the memory controller to allow it to performthe required translations. Either method may be used. Addresstranslation is made most convenient if prior to sending a string moveinstruction off chip, the processor takes string moves which cross pageboundaries and breaks them up into independent string move operations,each staying within a virtual page. This function may also be performedby logic associated with the bus interface unit 66.

While the string move operation is being performed off-chip, theprocessor may be able to execute other instructions in the instructionpool 80 that do not reference source or destination addresses. In asystem without caching, later instructions which do reference source ordestination memory addresses for stores or loads will be sent to thememory controller, which may be configured to completely service anypending string move operation prior to performing other memory accesses.

The presence of data caches 72, 74 require additional consideration.Coherency must be maintained between cached data and its counterpart inmain memory to ensure proper processor operation. In a system configuredto send all string move operations to an off chip memory controller, thetreatment of cached data will vary with the cache write policies. In asystem using a write through policy, all writes to cached addresses areautomatically also sent to main memory. In this case, an off chip stringmove will be certain to be moving the correct data. However, theprocessor will still be required to invalidate any cache linescontaining data from destination addresses.

A write back policy, where cached data is marked modified in the cache,but is not written back to main memory unless required, is a more commoncache write policy. In this case, any modified cache lines involved inthe string move will need to be written back to main memory. This may bedone prior to initiating the string move off chip. Alternatively, thestring move operation may be treated by the memory controller in amanner analogous to a non-processor memory access from, for example, aPCI bus master. Conventional memory controllers are already configuredto perform snoop cycles, wherein a memory address being accessed by someother device is sent to the processor, which checks to see if the databeing accessed exists in a modified state in a data cache. If a snoophit occurs, the data in the cache is written back to main memory beforethe other device accesses that memory location. The same procedure maybe performed by the memory controller when it is processing a stringmove operation. As the operation progresses, source addresses could beperiodically sampled by the processor to detect the presence of modifiedcached data which is to be moved. A snoop hit results in a cache linewrite back prior to continuing the string move operation. This will notnecessarily slow the operation significantly, as each snoop cycleanalyzes an entire cache line. It will be appreciated that in this caseas well cache lines containing destination addresses need to beinvalidated.

For off chip string manipulation in the processor architectureillustrated in FIG. 5, it will therefore be advantageous to includestring instruction execution circuitry both in the bus interface unitand in the off chip memory controller. This is true even if the actualdata movement is performed only off chip. The circuitry on the off chipmemory controller may be utilized to perform the actual datamanipulation, while the on-chip string instruction circuitry may be usedto update registers in the register file 88, and control any requiredpre-execution cache line write backs.

When the source string is entirely present in a data cache on theprocessor, it would be optimal to perform the string manipulation in thecache memory without performing the string instruction in the externalmemory. One advantageous method of performing a string move quickly oncached data is to utilize virtual data movement by simply writing newcache tag values into the cache tag memory to indicate the destinationaddresses. When this can be done, no time consuming data reads andwrites need to be performed.

The principles of this process may be illustrated most clearly using asimple example of a fully associative cache memory having a one bytecache line size. In this example, a cache tag memory stores the mainmemory address of each byte in the cache. Because the cache is fullyassociative, a byte from any main memory address may be stored in anyone of the locations in the cache. In a system implementing a write backcache policy, moving a byte of data which is present in the cache may beaccomplished by simply overwriting the source address stored in the tagmemory location associated with the byte with the appropriatedestination address, and marking the line modified. To move an entirestring of bytes, each tag memory location corresponding to each byte ofthe string may be updated with the appropriate destination address, andthe lines may again be marked modified.

Most processing systems use set associative rather than fullyassociative caches, and have cache line sizes longer than one byte.Implementing such virtual data movement in these environments involvesadditional considerations which are illustrated in FIG. 6. This Figureillustrates an 8 kB, two-way set associative cache with a 32 byte cacheline. This corresponds to the configuration of the L1 cache in thePentium Pro processor. In one embodiment, the main memory addresscomprises 32 bits. Of these 32 bits, the 20 most significant comprisethe tag, and the next 7 bits may be termed the index. The 5 leastsignificant bits are an offset, and define a specific byte within a 32byte cache line. The data memory portions 90, 92 of the cache eachcomprise sets of 128 cache lines. With a two-way set associative cacheas illustrated in FIG. 6, there is one location in each data memory 90,92 where data from a main memory address having a given index is allowedto reside.

FIG. 6 illustrates how a high speed string move may be performed byaltering the location of cached data a cache line at a time, rather thanin a conventional manner of a byte, word or doubleword at a time. Ingeneral, string moves of cached data may be performed by realigning themoved cache lines to their proper offsets, moving the cached data to acache memory location identified with the appropriate destination index,and adjusting cache tag values to reflect proper destination addresstags. As a specific example, a source string 94 of 178 bytes may beginat an address having a tag of decimal 0, an index of decimal 2, and anoffset of decimal 2. The first byte of this string will thus reside atlocation 96 of FIG. 6. For this example, we may further assume that thestarting destination address has a tag of decimal 1, an index of decimal121, and an offset of decimal 28. The 178 byte source string 94 willtherefore be moved to a destination block of addresses 98, beginning atlocation 100 of FIG. 6. This string move operation is an example of themost general type of string move, as each byte of source data is movedto a destination address having a different tag, index, and offset.

The move operation begins by reading out the 30 source bytes from thefirst source cache line 102. These bytes are then routed to a byteoriented barrel shifter 104, where they are shifted by an amount equalto the change in offset between the starting source address and startingdestination address. In this example, the shift would be 26 bytes. The26 spill bytes shifted out during this procedure are stored in aregister 106. To accommodate all possible changes in offset addresses,this register will have a capacity of one byte less than the cache linesize, 31 bytes in this example.

Following the shift, the four bytes which were not spilled to theregister 106 are stored in the first destination cache line 108 startingat the first destination address at location 100. If the destinationcache line is valid prior to the move, it must be marked modified toindicate the content alteration resulting from the four newly storedbytes of data. If this overwritten destination data is not cached, aline fill of the first destination line could be performed prior tostarting the move operation, or the first four bytes moved could bewritten back to main memory and not cached.

The string move operation then continues by reading out the next sourcecache line 110. This cache line is also barrel shifted by 26 bytes, withthe shift being filled by the 26 bytes stored in the register 106 fromthe previous shift operation. Once again, the 26 new spill bytes arestored in the register 106. This shifted cache line is then stored inthe next destination cache line 112. Because in this step the entiredestination cache line 112 has been filled with source data, no concernsabout the presence of valid data for a portion of this cache line arise.If the destination data is not present in the cache, the tag associatedwith this cache line 112 will be updated to reflect the destination tagaddress (decimal 1 in this example), and the line will be markedmodified. If the destination data was cached, the line 112 can simply bemarked modified.

The move process continues by reading the next source cache line 114,and performing another 26 byte shift which spills 26 new bytes into theregister 106, and is filled with the content of the register 106 fromthe prior shift operation. At the end of the process, the last cacheline 116 is read out. Even though 12 bytes of this cache line comprisedata which is not part of the move instruction, the whole cache line 116may be read out and shifted the same 26 byte shift. The barrel shiftedoutput of this operation will be stored in destination cache line 118.There will now be 26 bytes remaining in the register 106, with the top12 bytes being non-source data from the last portion 120 of the lastsource cache line 116. The final step in the move process will bewriting the 14 bottom source data bytes from the register 106 into thelast destination cache line 122. Because only a portion of the lastcache line 122 is modified, it may be treated as described above withrespect to the first cache line 108. Either a line fill can be performedprior to writing the remainder of the source data from the register 106to the line 122, or the remainder of the source data in the register 106may be written back to main memory and not cached.

It will be appreciated that string moves of long strings may beperformed very quickly with this processor design. If the cache read,barrel shift, and cache write are pipelined, the move may proceed at arate of one cache line per processor cycle. It is also apparent thatdepending on the source and destination addresses, certain moveoperations can be performed with very simple operations, often withoutrequiring the barrel shifting step. If the move involves an integralnumber of cache lines, and the starting source address and destinationaddress have offsets of 0, a move will involve simply a tag update and aset of cache line moves to the appropriate cache index locations. Inthis 0 offset start and destination situation, even the cache line moveswill be avoided in either a fully associative cache, or in a setassociative cache where the start and destination indexes of the bytesin the string are the same. In these cases, no cache data reads orwrites will need to be performed.

Source overwrite conditions must be considered where the set of sourceaddresses and destination addresses of the move overlap. When theinvention is implemented in a system using a direct mapped cache, thisproblem is most significant, because there will only be one cache memorylocation to move the source data to, and this destination location maystore source data which has not yet been moved. One solution to thisproblem when using a direct mapped cache would be to detect these sourceoverwrite conditions, and move the string starting with either the firstbyte of the source data and moving toward the last byte, or startingwith the last byte of source data and moving toward the first byte,depending on the direction of the data move. In a fully associativecache design, source overwrites can be avoided by always moving data tocache memory locations away from the cached source block. In setassociative caches, source overwrites may be avoided by writing thesource data to cache memory locations associated with a different setthan the source string is associated with. This is the procedureillustrated in FIG. 6.

Based on the foregoing, it will be understood that many implementationoptions are available for performing efficient string moves in aprocessing system with data caches. As discussed above, one option is toperform all moves external to the processor, with appropriate writebacks and invalidation occurring before or during the move operation.Alternatively, source strings which are resident in the cache can behandled entirely by updating the cache memory as described above. It mayfurther be desirable to only perform some string moves with thedescribed cache updating methods depending on the source and destinationaddresses and the length of the string to be moved. Furthermore, asource string of which only a portion is cached may have that portionwritten back to main memory if in a modified state for an off-chipstring move, or the un-cached portion may be cached with appropriateline fills prior to performing the move operation in the cache. It mayalso be desirable to perform some string moves in a conventionalsequential manner, and some in accordance with the methods describedherein.

Another string operation which is performed inefficiently inconventional processors is a string search for a specified byte, word,or doubleword. In the Pentium Pro, for example, the REP SCAS instructionwill sequentially subtract bytes in memory beginning at a selected startaddress from a test byte stored in the processor register file 88 (FIG.5). In response to the result of the subtraction, flags in a statusregister also in the register file 88 are set or cleared. As with themove operation, the start address, which is specified in the DI registerdiscussed above, is incremented or decremented with each comparison, andthe process continues until a matching byte is found. When such amatching byte is found, a zero flag is set, the operations terminate,and the address in the DI register corresponds to the address containingthe matching byte.

In accordance with the invention, this process can also be optimized inview of the main memory technology used in the system by performing thisstring manipulation instruction in a string execution unit associatedwith the bus interface unit or an off-chip memory controller. As with astring move, block reads of data for comparison may be performed,speeding the data access process for data stored in external mainmemory. Once a match is found, the DI register or its equivalent couldbe loaded from the memory controller with the address of the matchingdata address.

To facilitate rapid string searches of cached data, the cache memory maybe equipped with a set of byte comparators or subtractors. Thisembodiment of the invention is illustrated in FIG. 7. A set of datacomparators 132 are provided which are coupled to the cache data memory.There is one comparator for each byte of the cache line. The comparatorseach have one input for receiving a designated byte from a cache line,and one input for receiving a test byte from the string executioncircuitry. The outputs of the comparators are coupled to a decoder 134which has as an output the address of the matching byte, if a matchingbyte is present. With this system, an entire cache line may be comparedto a test data string in a single cycle.

If a string scan instruction is sent to an off-chip memory controller,as in some embodiments of the invention, the memory controller mayinstruct the processor to perform a search of a cache line by performinga bus cycle analogous to a standard snoop cycle. In a conventional snoopcycle, a control signal is asserted by the memory controller initiatingthe snoop, after which the memory controller presents an address to theprocessor. The processor then checks the cache tag memory to see if thedata at that address is present in a modified line in the cache. A cachehit to a modified line causes the processor to assert a second controlsignal which is routed to the memory controller.

Similarly, in a string scan request made to the processor, a bus cyclemay be initiated which presents a string scan starting address and thecomparison data. This operation may be termed a “string snoop”.Alternatively, just the starting address may be sent if the comparisondata is stored in a temporary register in the processor when the stringscan instruction is sent to the external string execution logic. Theprocessor could indicate to the memory controller the presence of amatch after performing a byte by byte cache line comparison in a mannersimilar to a cache hit in a snoop cycle, although advantageously anindication of both the presence of the data and the presence or absenceof a match should be indicated to the external circuitry in response toa string snoop bus cycle. The address output of the decoder 134 may beforwarded to the external string execution circuitry when a match isfound. This address may then be loaded into the DI register in theprocessor register file. If more than one match appears in the cacheline data being searched, the decoder may be configured to output theaddress of the matched byte having the lowest address. In this way, thefirst matching byte of the string will be specified.

Of course, the handling of the string scan instruction will changedepending on the length of the test string the source data is to becompared to, as well as the starting address of the source data. Fortest strings longer than one byte, the comparator outputs may beanalyzed in a coupled manner such that the compare data may be of word,doubleword, or quadword size may be used. In these situations, thedecoder 134 may be configured to detect a match only when a string ofmatches of appropriate length is detected. If subtractors rather thancomparators are used, the byte subtractors can again be coupled tosubtract words or doublewords for example, instead of individual bytes.

If the starting address of the string to be searched is aligned with acache line boundary, i.e., has a 0 offset, then the compare data can besimply replicated as required for input to the set of comparators 132.For non-aligned strings, the compare data may be aligned to match theoffset of the string starting address prior to the compare operation,and replicated as before to provide inputs to all the remainingcomparators. Of course, if the test string is only one byte long, noalignment will be required regardless of the offset of the startingaddress of the string to be searched.

String moves and string scans may therefore be performed with improvedefficiency, while retaining cache coherency. The foregoing descriptiondetails certain embodiments of the invention. It will be appreciated,however, that no matter how detailed the foregoing appears in text, theinvention can be practiced in many ways. As is also stated above, itshould be noted that the use of particular terminology when describingcertain features or aspects of the present invention should not be takento imply that the terminology is being re-defined herein to berestricted to including any specific characteristics of the features oraspects of the invention with which that terminology is associated. Thescope of the present invention should therefore be construed inaccordance with the appended claims and any equivalents thereof.

1. A cache memory comprising: a data memory configured to hold cachelines comprising a plurality of bytes of cache data; a plurality ofcomparators, wherein each comparator has a first input coupled to saiddata memory such that each comparator receives one of said plurality ofbytes of cache data via its associated first input, and wherein eachcomparator has a second input coupled to a second data source, such thatthe cache line may be compared to a test data string received from thesecond data source; and a decoder coupled to an output of eachcomparator, the decoder configured to identify a location in the cacheline that contains cache data that matches the test data string whenmatches from at least two of the plurality of comparators are detectedin a comparison operation.
 2. The cache memory of claim 1, wherein thetest data string received from the second data source comprises aplurality of bytes.
 3. The cache memory of claim 2, wherein the testdata string received from the second data source is a doubleword.
 4. Thecache memory of claim 1, wherein the number of comparators is equal tothe number of bytes in the cache line.
 5. The cache memory of claim 1,wherein the entire cache line is compared to the test data stringreceived from the second data source in one clock cycle.
 6. The cachememory of claim 1, wherein the data memory comprises a Level 1 cache. 7.A cache memory for comparing a data value with data in a cache memory,the cache memory comprising: a cache data memory configured to hold atleast one cache line comprising a plurality of bytes of data; a datasource configured to hold a data value, wherein the data value comprisesfewer bytes than the cache line; a plurality of comparators configuredto compare the cache line to the data value, each comparator having afirst input coupled to said cache data memory and configured to receiveat least one of said plurality of bytes of data, a second input coupledto the data source and configured to receive at least a portion of thedata value from the data source, and an output; and a decoder coupled tothe outputs of the plurality of comparators and configured to identify aportion of the cache line that matches at least a portion of the datavalue when matches from at least two comparators are detected during acomparison operation.
 8. The cache memory of claim 7, wherein the datavalue comprises a word.
 9. The cache memory of claim 7, wherein thenumber of the plurality of comparators is equal to the number of bytesin the cache line.
 10. The cache memory of claim 7, wherein the cacheline is compared to the data value in one clock cycle.
 11. The cachememory of claim 7, wherein the data source comprises a processor. 12.The cache memory of claim 7, wherein the cache data memory comprises aLevel 1 cache.
 13. A method for comparing cache memory data in a digitalprocessing system with a test data string, the method comprising:receiving an instruction to perform a compare operation, saidinstruction comprising a starting address and a test data string for usein said compare operation; routing the instruction to a data stringmanipulation circuit; routing the starting address for use in thecompare operation from the data string manipulation circuit to a cachememory; aligning the test data string with an offset of the startingaddress prior to said compare operation; comparing the test data stringwith cached data stored in a cache line of the cache memory, whereinsaid test data string comprises fewer bytes than the cache line; androuting an address of at least a portion of the cached data stored inthe cache line of the cache memory that matches the test data string tothe data string manipulation circuit.
 14. The method of claim 13,wherein the data string manipulation circuit comprises a bus interfaceunit.
 15. The method of claim 13, wherein the data string manipulationcircuit comprises a memory controller.
 16. The method of claim 13,wherein said act of comparing is performed by a plurality ofsubtractors.
 17. The method of claim 13, wherein said act of comparingis performed by a plurality of comparators.
 18. The method of claim 17,wherein the number of comparators is equal to the number of bytes in thecache line.
 19. The method of claim 13, wherein said act of comparing isperformed in one clock cycle.
 20. The method of claim 13, wherein saidact of routing an address of the matching cached data comprises routingthe lowest numbered address if there are a plurality of matches to thecache line.
 21. A method for comparing a string of data in a cachememory with a test data string, the method comprising: receiving aninstruction to perform a compare operation, said instruction comprisinga starting address for use in said compare operation; routing theinstruction to a data string manipulation circuit; routing the startingaddress for use in the compare operation from the data stringmanipulation circuit to a cache memory array; aligning a test datastring with data stored in the cache memory array prior to said compareoperation; comparing the test data string with the data stored in thecache memory array; and routing an address of cached data matching thetest data string to the data string manipulation circuit.
 22. The methodof claim 21, additionally comprising routing the test data string fromthe data string manipulation circuit to the cache memory array.
 23. Themethod of claim 21, wherein the data string manipulation circuitcomprises a bus interface unit.
 24. The method of claim 21, wherein thedata string manipulation circuit comprises a memory controller.
 25. Themethod of claim 21, wherein said act of comparing is performed with aplurality of comparators.
 26. The method of claim 21, wherein said actof routing an address of the matching cached data comprises routing thelowest numbered address if there are a plurality of matches in the cachememory array.
 27. The method of claim 21, wherein said act of routing anaddress of cached data matching the test data is performed by a decoder.28. A cache memory comprising: a data source means for storing a testdata; a cache memory means for storing at least one cache linecomprising a plurality of bytes of data; a means for comparing the testdata with the plurality of bytes of data, the means for comparingcoupled to the data source means and to the cache memory means; and ameans for decoding coupled to the means for comparing, wherein the meansfor decoding is capable of identifying respective addresses of multipleones of the plurality of bytes of data of the cache line that match atleast a portion of the test data.
 29. The cache memory of claim 28,wherein the means for comparing comprises a plurality of comparators.30. The cache memory of claim 28, wherein the means for comparingcomprises a plurality of subtractors.
 31. The cache memory of claim 28,wherein the data source means comprises an external string executionunit.
 32. The cache memory of claim 31, wherein the string executionunit comprises a bus interface unit.
 33. The cache memory of claim 31,wherein the string execution unit comprises a memory controller.
 34. Thecache memory of claim 31, wherein the means for decoding is configuredto forward a cache line address of the matching data to the stringexecution unit.
 35. The cache memory of claim 28, wherein the test datacomprises a word.
 36. The cache memory of claim 28, wherein the entirecache line is compared to the test data in one clock cycle.
 37. Thecache memory of claim 28, wherein the cache memory means comprises aLevel 1 cache.